package us.gaaoc.framework.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import us.gaaoc.framework.model.CaseRecordAction;
import us.gaaoc.framework.util.HibernateUtil;

@Configurable(dependencyCheck=true,autowire=Autowire.BY_TYPE)
@Scope("prototype")
@Component
public class HibernateDAOFactory extends DAOFactory {
	
	Logger LOG = Logger.getLogger(HibernateDAOFactory.class);

	protected HibernateDAOFactory() {}
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	

	 
	public  Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
		// To run Tester class add the following line and uncomment the HibernateUtil class and add jdbc driver in project properties.
		//return HibernateUtil.getSessionFactory().getCurrentSession();
	}
	
	public PersonDAO getPersonDAO() {
		return new PersonDAOHibernate().setSession(getCurrentSession());
	}

	public CaseRecordHistoryDAO getCaseRecordHistoryDAO() {
		return new CaseRecordHistoryDAOHibernate().setSession(getCurrentSession());
	}
	
	public CaseRecordDAO getCaseRecordDAO(String courtUuid) {
		return new CaseRecordDAOHibernate(courtUuid).setSession(getCurrentSession());
	}
	
	public CourtDAO getCourtDAO() {
		return new CourtDAOHibernate().setSession(getCurrentSession());
	}
	
	public DocumentsDAO getDocumentsDAO() {
		return new DocumentsDAOHibernate().setSession(getCurrentSession());
	}
	
	public FilingSearchDAO getFilingSearchDAO() {
		return new FilingSearchDAOHibernate().setSession(getCurrentSession());
	}

	public NotificationsDAO getNotificationsDAO() {
		return new NotificationsDAOHibernate().setSession(getCurrentSession());
	}

	public OrganizationsDAO getOrganizationsDAO() {
		return new OrganizationsDAOHibernate().setSession(getCurrentSession());
	}
	
	public PublicNotificationsDAO getPublicNotificationsDAO() {
		return new PublicNotificationsDAOHibernate().setSession(getCurrentSession());
	}

	public RolesDAO getRolesDAO() {
		return new RolesDAOHibernate().setSession(getCurrentSession());
	}
	
	public PersonParticipantsDAO getPersonParticipantsDAO() {
		return new PersonParticipantsDAOHibernate().setSession(getCurrentSession());
	}

	public OrgParticipantsDAO getOrgParticipantsDAO() {
		return new OrgParticipantsDAOHibernate().setSession(getCurrentSession());
	}
	
	public ProfileDAO getProfileDAO(){
		return new ProfileDAOHibernate().setSession(getCurrentSession());
	}
	
	public CourtEventsDAO getCourtEventsDAO(){
		return new CourtEventsDAOHibernate().setSession(getCurrentSession());
	}

	public CourtHearingNegotiationsDAO getCourtHearingNegotiationsDAO(){
		return new CourtHearingNegotiationsDAOHibernate().setSession(getCurrentSession());
	}
	
	public PersonAddressDAO getPersonAddressDAO(){
		return new PersonAddressDAOHibernate().setSession(getCurrentSession());
	}
	
	public OrganizationAddressDAO getOrganizationAddressDAO(){
		return new OrganizationAddressDAOHibernate().setSession(getCurrentSession());
	}
	
	public AttorneyDAO getAttorneyDAO(){
		return new AttorneyDAOHibernate().setSession(getCurrentSession());
	}
	
	public JudgeDAO getJudgeDAO(){
		return new JudgeDAOHibernate().setSession(getCurrentSession());
	}
	
	public SheriffDAO getSheriffDAO(){
		return new SheriffDAOHibernate().setSession(getCurrentSession());
	}

	 
	public CourtHearingNegotiationStatusDAO getCourtHearingNegotiationStatusDAO() {
		return new CourtHearingNegotiationStatusDAOHibernate().setSession(getCurrentSession());
	}
 
	public CaseRecordEventTypeDAO getCaseRecordEventTypeDAO() {
		return new CaseRecordEventTypeDAOHibernate().setSession(getCurrentSession());
	}
	@Override
	public FilingAuditDAO getFilingAuditDAO() {
		return new FilingAuditDAOHibernate().setSession(getCurrentSession());
	}

 
	public CaseRecordStatusDAO getCaseRecordStatusDAO() {
		return new CaseRecordStatusDAOHibernate().setSession(getCurrentSession());
	}
	
	@Override
	public ParticipantRelationshipDAO getParticipantRelationshipDAO() {
		return new ParticipantRelationshipDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public AddressTypeDAO getAddressTypeDAO() {
		return new AddressTypeDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public CourtEventTypeDAO getCourtEventTypeDAO() {
		return new CourtEventTypeDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public DocumentTypeDAO getDocumentTypeDAO() {
		return new DocumentTypeDAOHibernate().setSession(getCurrentSession());
	}
	
	public SignaturesDAO getSignaturesDAO() {
		LOG.info("2. Inside the getSignaturesDAO method of the SignaturesDAO");
		return new SignaturesDAOHibernate().setSession(getCurrentSession());
	}
	
	public DocumentStatusDAO getDocumentStatusDAO() {
		return new DocumentStatusDAOHibernate().setSession(getCurrentSession());
	}
	
	public CourtSealDAO getCourtSealDAO() {
		return new CourtSealDAOHibernate().setSession(getCurrentSession());
	}

	public CounterDAO getCounterDAO() {
		LOG.info("creating a session so the table counter can be accessed, this session is the current session");
		return new CounterDAOHibernate().setSession(getCurrentSession());
	}

	public CounterPerSignerDAO getCounterPerSignerDAO() {
		LOG.info("getting the current session so the table counterPerSigner can be accessed....");
		return new CounterPerSignerDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public CaseRecordTypeDAO getCaseRecordTypeDAO() {
		return new CaseRecordTypeDAOHibernate().setSession(getCurrentSession());
	}

	public DocumentSigConfigDAO getDocumentSigConfigDAO() {
		return new DocumentSigConfigDAOHibernate().setSession(getCurrentSession());
	}
	@Override
	public ExternalCaseRecordToCaseRecordDAO getExternalCaseRecordToCaseRecordDAO() {
		return new ExternalCaseRecordToCaseRecordDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public LegalPreparerDAO getLegalPreparerDAO() {
		return new LegalPreparerDAOHibernate().setSession(getCurrentSession());
	}

	public LdapDirectoryPersonDAO getLdapDirectoryPersonDAO() {
		return new LdapDirectoryPersonDAOHibernate().setSession(getCurrentSession());
	}
	
	public DocumentPackageDAO getDocumentPackageDAO() {
		return new DocumentPackageDAOHibernate().setSession(getCurrentSession());
	}
	
	public DocPageRangeDAO getDocPageRangeDAO() {
		return new DocPageRangeDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public DocumentCategoryDAO getDocumentCategoryDAO() {
		return new DocumentCategoryDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public DocumentInstanceDAO getDocumentInstanceDAO() {
		return new DocumentInstanceDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public DocumentLocalCodeDAO getDocumentLocalCodeDAO() {
		return new DocumentLocalCodeDAOHibernate().setSession(getCurrentSession());
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getLocalCaseCategoryDAO()
	 */
	@Override
	public LocalCaseCategoryDAO getLocalCaseCategoryDAO() {
		return new LocalCaseCategoryDAOHibernate().setSession(getCurrentSession());
	}
	
	@Override
	public LocalCaseDivisionDAO getLocalCaseDivisionDAO() {
		return new LocalCaseDivisionDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public LocalCaseFilingTypeDAO getLocalCaseFilingTypeDAO() {
		return new LocalCaseFilingTypeDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public LocalCaseTypeDAO getLocalCaseTypeDAO() {
		return new LocalCaseTypeDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public LocalCourtEventTypeDAO getLocalCourtEventTypeDAO() {
		return new LocalCourtEventTypeDAOHibernate().setSession(getCurrentSession());
	
	}

	@Override
	public LocalParticipantRelationshipDAO getLocalParicipantRelationshipDAO() {
		return new LocalParticipantRelationshipDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public CaseRecordExternalCaseRecordNumberDAO getCaseRecordExternalCaseRecordNumberDAO() {
		return new CaseRecordExternalCaseRecordNumberDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public PersonHashedSSNDAO getPersonHashedSSNDAO() {
		return new PersonHashedSSNDAOHibernate().setSession(getCurrentSession());
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getAddressDAO()
	 */
	@Override
	public AddressDAO getAddressDAO() {
		return new AddressDAOHibernate().setSession(getCurrentSession());
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getAddressCategoryDAO()
	 */
	@Override
	public AddressCategoryDAO getAddressCategoryDAO() {
		return new AddressCategoryDAOHibernate().setSession(getCurrentSession());
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getVisualMarkDAO()
	 */
	@Override
	public VisualMarkDAO getVisualMarkDAO() {
		return new VisualMarkDAOHibernate().setSession(getCurrentSession());
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getVisualMarkCategoryDAO()
	 */
	@Override
	public VisualMarkCategoryDAO getVisualMarkCategoryDAO() {
		return new VisualMarkCategoryDAOHibernate().setSession(getCurrentSession());
	}

	public LdapDirectoryOrganizationDAO getLdapDirectoryOrganizationDAO() {
		return new LdapDirectoryOrganizationDAOHibernate().setSession(getCurrentSession());
	}

	/*
	 * (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DAOFactory#getDocumentBinariesDAO()
	 */
	@Override
	public DocumentBinariesDAO getDocumentBinariesDAO() {
		return new DocumentBinariesDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public PersonOrganizationsDAO getPersonOrganizationsDAO() {
		return new PersonOrganizationsDAOHibernate().setSession(getCurrentSession());
	}

	@Override
	public CaseRecordActionDAO getCaseRecordActionDAO() {
		return new CaseRecordActionDAOHibernate().setSession(getCurrentSession());
	}
	
	@Override
	public SignatureImageDAO getSignatureImageDAO() {
		return new SignatureImageDAOHibernate().setSession(getCurrentSession());
	}
}
